import { HttpMethodsTD } from '@/http/types';
import { StoreRequest2 } from '@/store';
import { Store } from 'vuex';

interface Label {
  name: string;
  id: string;
}
// 标签列表
export const apiCssLabelList = StoreRequest2<void, Label[]>({
  name: 'cssLabelList',
  method: HttpMethodsTD.GET,
  url: '/css/labels',
  transformResponse: res => res.data.data,
});

// 标签添加
export const apiCssLabelAdd = StoreRequest2<{ data: { name: string } }, { name: string; id: string }>({
  name: 'cssLabelAdd',
  method: HttpMethodsTD.POST,
  url: '/css/label',
});

// 标签更新
export const apiCssLabelUpdate = StoreRequest2<Label, Label>({
  name: 'cssLabelUpdate',
  method: HttpMethodsTD.PUT,
  url: '/css/label',
});

interface Item {
  label?: string;
  css?: string;
  html?: string;
  pic?: string;
  id?: string;
}
// 条目列表
export const apiCssItemList = StoreRequest2<{ params: { page: number; size: number; label: string } }, { list: Item[] }>({
  name: 'cssItemList',
  method: HttpMethodsTD.GET,
  url: '/css/items',
  transformResponse: res => res.data.data.list,
});

// 条目添加
export const apiCssItemAdd = StoreRequest2<{ data: Item }, Item>({
  name: 'cssItemAdd',
  method: HttpMethodsTD.POST,
  url: '/css/item',
});

// 条目更新
export const apiCssItemUpdate = StoreRequest2<{ data: Item }, Item>({
  name: 'cssItemUpdate',
  method: HttpMethodsTD.PUT,
  url: '/css/item',
});

// 条目获取
export const apiCssItemGet = StoreRequest2<{ params: { id: string } }, Item>({
  name: 'cssItemGet',
  method: HttpMethodsTD.GET,
  url: '/css/item',
});

export const apiCssUpload = StoreRequest2<{ data: FormData }, { [s: string]: string }>({
  name: 'cssUpload',
  method: HttpMethodsTD.POST,
  url: '/css/upload',
  headers: {
    'Content-Type': 'multipart/form-data',
  },
});
